import React, { Component } from 'react';
import { getList } from '../../api'
import List from '../../components/List'
class Index extends Component {
	state = {
		list: []
	}
	async getList() {
		const resp = await getList()
		const { data } = resp.data
		this.setState({ list: data })
	}
	toDetail = (v) => {
		// 跳转详情
		this.props.history.push({
			// 跳转路径
			pathname: '/detail',
			// 发送的数据（隐身路由）
			state: v
		})
	}
	componentDidMount() {
		this.getList()
	}
	render() {
		const { list } = this.state
		return (
			<div className="home">
				<List list={list} toDetail={ this.toDetail }></List>
			</div>
		);
	}
}

export default Index;
